﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="wucContas.ascx.cs" Inherits="WebControl_wucContas" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<script type="text/javascript">
    function validar(){
        if (
             (!<%= txt_NomeConta.ClientID %>.validate()) ||
             (!<%= cbxTipoConta.ClientID %>.validate())
           )
        {
            //Ext.Msg.alert('Validação de campos', 'O campo descrição é obrigatório.');
            return false;
        }
        return true;
    }
    function deleta(button, e) {
        Ext.Msg.confirm('Exclusão do Registro','Deseja realmente excluir o registro?',
            continueAjaxEvent.createDelegate(button, [button, e], true), 
            button
        );
        return false;
    }
    function continueAjaxEvent(btnId, text, sender, e) {
      if (btnId == 'yes') {
          sender.ajaxEvents.click.fn.apply(sender, [sender, e]);
      }
    }
</script>
<%--Store Para Popular o Grid--%>
<ext:Store ID="strGridConta" runat="server" 
    AutoLoad="true"
    RemoteSort="true" 
    OnRefreshData="strGridConta_RefreshData">
    <Reader>
        <ext:JsonReader ReaderID="cta_Id_Conta">
            <Fields>
                <ext:RecordField Name="cta_Id_Conta" Type="Int" />
                <ext:RecordField Name="cta_tx_NomeConta" Type="String" />
            </Fields>
        </ext:JsonReader>
    </Reader>
</ext:Store>
<%--Painel como Grid--%>
<ext:Panel ID="pnlCadConta" runat="server">
    <TopBar>
        <ext:Toolbar runat="server" ID="tbAcoesConta">
        <Items>
            <ext:ToolbarButton runat="server" ID="btnNovoConta" 
                Text="Novo"
                Icon="Add">
                <AjaxEvents>
                    <Click OnEvent="NovoContaClick">
                        <EventMask ShowMask="true" />
                    </Click>
                </AjaxEvents>
            </ext:ToolbarButton>
            <ext:ToolbarButton runat="server" ID="btnEditarConta" 
                Text="Editar"
                Enabled="false"
                Icon="BuildingEdit">
                <AjaxEvents>
                    <Click OnEvent="EditarContaClick">
                        <EventMask ShowMask="true" />
                    </Click>
                </AjaxEvents>
            </ext:ToolbarButton>
            <ext:ToolbarFill />
            <ext:ToolbarButton runat="server" ID="btnDeletarConta"  
                Text="Excluir"
                Enabled="false"
                Icon="Delete">
              <Listeners>
                  <Click Fn="deleta" />
              </Listeners>
              <AjaxEvents>
                  <Click OnEvent="DeletarContaClick" Success="if (!#{GridCadConta}.hasSelection()){#{btnDeletarConta}.disable();} #{GridCadConta}.reload();">
                  </Click>
              </AjaxEvents>
            </ext:ToolbarButton>
        </Items>    
        </ext:Toolbar>
    </TopBar>
    <Body>
        <ext:GridPanel ID="GridCadConta" runat="server" 
            StoreID="strGridConta" 
            Header="true" 
            Height="150"
            Width="380"
            AutoScroll="true">
            <ColumnModel ID="ColumnModel" runat="server">
                <Columns>
                    <ext:Column ColumnID="cta_Id_Conta" DataIndex="cta_Id_Conta" Header="Código"
                        Width="80" Sortable="true" />
                    <ext:Column DataIndex="cta_tx_NomeConta" Header="Descrição" Width="250" Sortable="true" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModel1" SingleSelect="true" runat="server">
                    <Listeners>
                        <RowSelect Handler="#{btnDeletarConta}.enable(); #{btnEditarConta}.enable();" />
                        <RowDeselect Handler="#{btnDeletarConta}.disable(); #{btnEditarConta}.disable();" />
                        <%--<RowDeselect Handler="if (!#{GridCadConta}.hasSelection()) {#{btnDeletarConta}.disable();#{btnEditar}.disable();}" />--%>
                    </Listeners>
                </ext:RowSelectionModel>
            </SelectionModel>
            <LoadMask ShowMask="true" Msg="Carregando..." />
            <SaveMask ShowMask="true" Msg="Salvando..." />
            <BottomBar>
                <ext:PagingToolBar ID="PagingToolBar1" runat="server" PageSize="10" StoreID="strGridConta" AutoWidth="true" />
            </BottomBar>
        </ext:GridPanel>
    </Body>
</ext:Panel>
<%--Formulário de Manipulação dos Dados--%>
<ext:Window ID="wdwDadosConta" runat="server" 
    Title="Dados Conta" 
    Width="400px"
    Height="250px"
    ShowOnLoad="false"
    Hidden="true"
    Modal="true"
    Resizable="false"
    BodyStyle="padding: 10px">
    <Body>
        <ext:FormLayout ID="frmLayConta" runat="server" LabelWidth="70">
            <ext:Anchor>
                <ext:TextField ID="txt_Id_Conta" runat="server"
                    FieldLabel="Código"
                    AllowBlank="false"
                    MsgTarget="Title"
                    Width="100px">
                </ext:TextField>
            </ext:Anchor>
            <ext:Anchor>
                <ext:TextField ID="txt_NomeConta" runat="server" 
                    FieldLabel="Descrição"
                    AllowBlank="false"
                    MsgTarget="Side"
                    Width="250px"
                    EmptyText="Informe o nome da conta">
                </ext:TextField>
            </ext:Anchor>
            <ext:Anchor>
                <ext:ComboBox ID="cbxTipoConta" runat="server" 
                    FieldLabel="Tipo Conta"
                    AllowBlank="false"
                    MsgTarget="Title"
                    Width="100px"
                    TriggerAction="All">
                    <Items>
                        <ext:ListItem Text="Corrente" Value="C" />
                        <ext:ListItem Text="Poupança" Value="P" />
                    </Items>
                </ext:ComboBox>
            </ext:Anchor>
            <ext:Anchor>
                <ext:TextField ID="txtCodBanco" runat="server" 
                    FieldLabel="Banco"
                    AllowBlank="true"
                    MsgTarget="Side"
                    Width="100px">
                </ext:TextField>
            </ext:Anchor>
            <ext:Anchor>
                <ext:TextField ID="txtCodAgencia" runat="server" 
                    FieldLabel="Agência"
                    AllowBlank="true"
                    MsgTarget="Side"
                    Width="100px">
                </ext:TextField>
            </ext:Anchor>
            <ext:Anchor>
                <ext:TextField ID="txtNumConta" runat="server" 
                    FieldLabel="Número"
                    AllowBlank="true"
                    MsgTarget="Side"
                    Width="100px">
                </ext:TextField>
            </ext:Anchor>
        </ext:FormLayout>
    </Body>
    <BottomBar>
        <ext:Toolbar runat="server" ID="tbarAcoesConta">
            <Items>
                <ext:ToolbarButton ID="btnWindowNovoConta" runat="server" Text="Novo" Icon="Add">
                    <AjaxEvents>
                        <Click OnEvent="NovoContaClick"></Click>
                    </AjaxEvents>
                </ext:ToolbarButton>
                <ext:ToolbarButton ID="btnSalvarConta" runat="server" Text="Salvar" Icon="Disk">
                    <AjaxEvents>
                        <Click OnEvent="SalvarContaClick" Before="return validar();" Success="#{GridCadConta}.reload();"></Click>
                    </AjaxEvents>
                </ext:ToolbarButton>
                <ext:ToolbarFill />
                <ext:ToolbarButton ID="btnFecharConta" runat="server" Text="Fechar" Icon="Cancel">
                    <Listeners>
                        <Click Handler="#{wdwDadosConta}.hide()" />
                    </Listeners>
                </ext:ToolbarButton>
            </Items>
        </ext:Toolbar>
    </BottomBar>
</ext:Window>
